package com.panda.business.controller.user;

import com.panda.business.domain.AccountInfo;
import com.panda.business.domain.DeviceStateInfo;
import com.panda.business.domain.req.DeviceStateInfoVo;
import com.panda.business.service.AccountService;
import com.panda.business.service.DeviceStateService;
import com.panda.common.annotation.Log;
import com.panda.common.core.controller.BaseController;
import com.panda.common.core.domain.AjaxResult;
import com.panda.common.enums.BusinessType;
import com.panda.framework.domain.base.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 手机设备状态Controller
 * 
 * @author panda
 * @date 2021-01-06
 */
@RestController
@RequestMapping("/business/device")
public class TblWechatAccountinfoController extends BaseController
{
    @Autowired
    private DeviceStateService service;

    @Autowired
    private AccountService accountService;

    /**
     * 查询手机设备状态列表
     */
    @GetMapping("/list")
    public PageBean<DeviceStateInfo> list(DeviceStateInfoVo vo)
    {
        PageBean<DeviceStateInfo> pageBean = service.queryDeviceStateInfo(vo);
        return pageBean;
    }


    /**
     * 获取手机设备状态详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:accountinfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        DeviceStateInfo info = service.findDeviceStateInfoByid(id);
        return AjaxResult.success(info);
    }

    /**
     * 新增手机设备状态
     */
    @PreAuthorize("@ss.hasPermi('business:accountinfo:add')")
    @Log(title = "手机设备状态", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeviceStateInfo info)
    {
        return service.insert(info);
    }

    /**
     * 修改手机设备状态
     */
    @PreAuthorize("@ss.hasPermi('business:accountinfo:edit')")
    @Log(title = "手机设备状态", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeviceStateInfo info)
    {
        service.update(info);
        return AjaxResult.success();
    }

    /**
     * 删除手机设备状态
     */
    @PreAuthorize("@ss.hasPermi('business:accountinfo:remove')")
    @Log(title = "手机设备状态", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        for(Long id:ids){
            service.delete(Integer.valueOf(String.valueOf(id)));
        }
        return AjaxResult.success();
    }

    /**
     * 绑定账号
     * @param id
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/binding" ,method = RequestMethod.POST)
    public boolean binding(Integer accountid, String ids, HttpServletRequest request){
        return service.binding(accountid,ids);
    }
}
